<template>
	<view class="search-container">
		<!-- 顶部搜索区域 -->
		<view class="search-header">
			<view class="search-input-wrapper">
				<text class="search-icon">🔍</text>
				<input 
					class="search-input" 
					placeholder="搜索名称，按法名称" 
					v-model="searchKeyword"
					focus
					@input="onInput"
					@confirm="onSearch"
				/>
			</view>
		</view>
		
		<!-- 最近搜索区域 -->
		<view class="recent-section">
			<text class="section-title">最近搜索</text>
			<view class="search-history">
				<view 
					class="history-item" 
					v-for="(item, index) in searchHistory" 
					:key="index"
					@tap="selectHistory(item)"
				>
					<text class="history-text">{{item}}</text>
				</view>
			</view>
		</view>
		
		<!-- 搜索结果区域 -->
		<view class="results-section" v-if="showResults">
			<text class="section-title">搜索结果</text>
			<view class="result-list">
				<view class="result-item" v-for="(result, index) in searchResults" :key="index">
					<text class="result-text">{{result}}</text>
				</view>
			</view>
		</view>
		
		<!-- 底部导航栏 -->
		<view class="bottom-nav">
			<view class="nav-item" @tap="goToHome">
				<text class="nav-icon">🏠</text>
				<text class="nav-text">首页</text>
			</view>
			<view class="nav-item" @tap="goToPractice">
				<text class="nav-icon">🎯</text>
				<text class="nav-text">练习</text>
			</view>
			<view class="nav-item" @tap="goToProfile">
				<text class="nav-icon">👤</text>
				<text class="nav-text">个人</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'Search',
	data() {
		return {
			searchKeyword: '',
			showResults: false,
			searchHistory: [
				'欧阳震华学员',
				'一字马练习', 
				'腿部'
			],
			searchResults: []
		}
	},
	methods: {
		onInput(e) {
			this.searchKeyword = e.detail.value;
			if (this.searchKeyword.trim()) {
				this.showResults = true;
				// 模拟搜索结果
				this.searchResults = [
					`${this.searchKeyword}相关课程`,
					`${this.searchKeyword}基础教学`,
					`${this.searchKeyword}进阶练习`
				];
			} else {
				this.showResults = false;
				this.searchResults = [];
			}
		},
		onSearch() {
			if (this.searchKeyword.trim()) {
				// 添加到搜索历史
				if (!this.searchHistory.includes(this.searchKeyword)) {
					this.searchHistory.unshift(this.searchKeyword);
					if (this.searchHistory.length > 10) {
						this.searchHistory = this.searchHistory.slice(0, 10);
					}
				}
				// 执行搜索
				console.log('搜索:', this.searchKeyword);
			}
		},
		selectHistory(keyword) {
			this.searchKeyword = keyword;
			this.onSearch();
		},
		goToHome() {
			uni.navigateBack();
		},
		goToPractice() {
			uni.navigateTo({
				url: '/pages/practice/practice'
			});
		},
		goToProfile() {
			uni.navigateTo({
				url: '/pages/profile/profile'
			});
		}
	}
}
</script>

<style scoped>
.search-container {
	background: linear-gradient(135deg, #FFE4E6 0%, #FFF0F2 100%);
	min-height: 100vh;
	padding: 0 30rpx 160rpx;
}

.search-header {
	padding: 80rpx 0 40rpx;
}

.search-input-wrapper {
	background: #FFFFFF;
	border-radius: 30rpx;
	padding: 24rpx 30rpx;
	display: flex;
	align-items: center;
	box-shadow: 0 4rpx 20rpx rgba(255, 107, 157, 0.1);
}

.search-icon {
	font-size: 32rpx;
	margin-right: 20rpx;
	color: #999999;
}

.search-input {
	flex: 1;
	font-size: 28rpx;
	color: #333333;
	border: none;
	outline: none;
}

.search-input::placeholder {
	color: #CCCCCC;
}

.recent-section {
	margin-bottom: 40rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
	margin-bottom: 30rpx;
	display: block;
}

.search-history {
	display: flex;
	flex-wrap: wrap;
	gap: 20rpx;
}

.history-item {
	background: #FFFFFF;
	border-radius: 40rpx;
	padding: 16rpx 30rpx;
	box-shadow: 0 2rpx 10rpx rgba(255, 107, 157, 0.1);
}

.history-text {
	font-size: 26rpx;
	color: #666666;
}

.results-section {
	margin-bottom: 40rpx;
}

.result-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.result-item {
	background: #FFFFFF;
	border-radius: 20rpx;
	padding: 30rpx;
	box-shadow: 0 4rpx 20rpx rgba(255, 107, 157, 0.1);
}

.result-text {
	font-size: 28rpx;
	color: #333333;
}

.bottom-nav {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #FFFFFF;
	display: flex;
	padding: 20rpx 0;
	box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.nav-item {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 10rpx 0;
}

.nav-item.active .nav-icon,
.nav-item.active .nav-text {
	color: #FF6B9D;
}

.nav-icon {
	font-size: 44rpx;
	margin-bottom: 8rpx;
	color: #999999;
}

.nav-text {
	font-size: 22rpx;
	color: #999999;
}
</style> 